import { tBool, tNum, tStr } from "~/models/types"
import { Value } from "~/models/value/Value"

export function literal(value: any): Value {
  if (Object.prototype.toString.call(value) === '[object String]') {
    return new Value(tStr, value)
  }
  else if (Object.prototype.toString.call(value) === '[object Number]') {
    return new Value(tNum, value)
  }
  else if (Object.prototype.toString.call(value) === '[object Object]') {
    throw "Object无法作为字面量"
  }
  else if (Object.prototype.toString.call(value) === '[object Boolean]') {
    return new Value(tBool, value)
  }
  else if (Object.prototype.toString.call(value) === '[object Array]') {
    throw "数组无法作为字面量"
  }
  else {
    console.error(value);
    throw new Error('literal: 未知的字面量类型')
  }
}